package com.dwxt.community.service;

import com.dwxt.common.util.*;
import com.dwxt.community.dao.*;
import com.dwxt.community.entity.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;

import java.util.*;

@Service
public class SignService {
    @Autowired
    private SignRecordMapper signRecordMapper;

    public boolean isSignToday(String userId) {
        SignRecordExample example = new SignRecordExample();
        example.createCriteria().andUserIdEqualTo(userId).andYearEqualTo(DateUtils.getYear(null)).andMonthEqualTo(DateUtils.getMonth(null))
                .andDayEqualTo(DateUtils.getDay(null));
        List<SignRecord> signRecords = signRecordMapper.selectByExample(example);
        return signRecords.size() > 0 ? true : false;

    }

    public void create(String userId) {
        SignRecord signRecord = new SignRecord();
        signRecord.setYear(DateUtils.getYear(null));
        signRecord.setMonth(DateUtils.getMonth(null));
        signRecord.setDay(DateUtils.getDay(null));
        signRecord.setCreateTime(new Date());
        signRecord.setUserId(userId);

        signRecordMapper.insert(signRecord);
    }

    public List<SignRecord> getSignRecord(String currentUserId) {
        SignRecordExample example = new SignRecordExample();
        example.createCriteria().andUserIdEqualTo(currentUserId).andYearEqualTo(DateUtils.getYear(null))
                .andMonthEqualTo(DateUtils.getMonth(null));
        return signRecordMapper.selectByExample(example);
    }
}
